<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="ctxPath" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>审批</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel = "Shortcut Icon" href="${ctxPath}/static/images/addUser.ico"/>
	<link rel="stylesheet" href="${ctxPath}/static/layui/css/layui.css" media="all">
</head>
<body>
<script src="${ctxPath}/static/layui/layui.js" charset="utf-8"></script>
<fieldset class="layui-elem-field layui-field-title"
		  style="margin-top: 20px;">
	<legend>审批界面</legend>
</fieldset>

<script src="${ctxPath}/static/js/jquery-1.11.1.min.js"></script>

<form id="userForm" class="layui-form"
	  action=""
	  method="post">

	<div class="layui-form-item">
		<label class="layui-form-label">当前任务ID:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text" id="taskId"
				   autocomplete="off"
				   value="${leave.taskId}" readonly
				   class="layui-input">
		</div>

	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">申请发起人:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text" id="initiatorName"
				   autocomplete="off"
				   value="${leave.initiatorName}" readonly
				   class="layui-input">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">开始时间:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text" id="startDate"
				   name="nickName"
				   value="${leave.startDate}" readonly
				   class="layui-input">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label">结束时间:</label>
		<div class="layui-input-block" style="width:450px;">
			<input type="text" id="endDate"
				    autocomplete="off"
				   value="${leave.endDate}" readonly
				   class="layui-input">
		</div>
	</div>

	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">请假原因:</label>
		<div class="layui-input-block">
      <textarea id="reason"
				readonly
				class="layui-textarea wd-550" >${leave.reason}</textarea>
		</div>
	</div>


	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" type="button"
					onclick="apprLeave('true');" >
				同意申请
			</button>
			<button class="layui-btn" type="button"
					onclick="apprLeave('false');" >
				拒绝申请
			</button>
		</div>
	</div>

	<div class="layui-form-item layui-form-text">
		<label class="layui-form-label">拒绝原因:</label>
		<div class="layui-input-block">
      <textarea id= "refuseReason"
				placeholder="请输入拒绝原因"
				class="layui-textarea wd-550"></textarea>
		</div>
	</div>


</form>

<script>
	function apprLeave( _flag ){
		var _taskId = $("#taskId").val();
		//{1} 当前用户部门ID
		var _deptId = '${user.dept.id}';
		//{2} 拒绝原因
		var _reason   = $("#refuseReason").val();
		//{3} 提交地址
		$.ajax(
				{
					url:'${ctxPath}/Leave/doApprove',
					type:'post',
					data:{
						deptId:_deptId,
						appFlag:_flag,
						refuseReason:_reason,
						taskId:_taskId
					},
					dataType:"json",
					success:function( json ){
						console.log( json );
						var ret = json['result'];
						if (ret == 'success') {
							alert('提交审批成功');
							window.location = "${ctxPath}/Leave/waitMyApprove";
						} else {
							var cause = json['cause'];
							alert('提交审批失败,原因：'+cause);
						}
					}
				}
		);
	}
</script>
